//Design By Do Trung --- Email : trungqn19852003@yahoo.com
//Ngày Design :5/4/2011 5:00:13 PM
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using System.Collections.Generic;
 
	/// <summary>
	/// </summary>
	public class HinhAnh_DA
	{
		public HinhAnh_DA() {}
#region 'Variables And Properties'
		 private int int_IdHinhAnh ;
		 public int IdHinhAnh
			{
			 get 	
				{
					 return this.int_IdHinhAnh;
				}
			 set 	
				{
					int_IdHinhAnh=value;
				}
			}
		 private int int_IDChuyenMuc ;
		 public int IDChuyenMuc
			{
			 get 	
				{
					 return this.int_IDChuyenMuc;
				}
			 set 	
				{
					int_IDChuyenMuc=value;
				}
			}
		 private string string_TenFile ;
		 public string TenFile
			{
			 get 	
				{
					 return this.string_TenFile;
				}
			 set 	
				{
					string_TenFile=value;
				}
			}
		 private string string_TenHienThi ;
		 public string TenHienThi
			{
			 get 	
				{
					 return this.string_TenHienThi;
				}
			 set 	
				{
					string_TenHienThi=value;
				}
			}
		 private string string_MoTa ;
		 public string MoTa
			{
			 get 	
				{
					 return this.string_MoTa;
				}
			 set 	
				{
					string_MoTa=value;
				}
			}
		 private string string_NgayUpload ;
		 public string NgayUpload
			{
			 get 	
				{
					 return this.string_NgayUpload;
				}
			 set 	
				{
					string_NgayUpload=value;
				}
			}
		 private string string_NgayCapNhat ;
		 public string NgayCapNhat
			{
			 get 	
				{
					 return this.string_NgayCapNhat;
				}
			 set 	
				{
					string_NgayCapNhat=value;
				}
			}
		 private bool bool_TrangThai ;
		 public bool TrangThai
			{
			 get 	
				{
					 return this.bool_TrangThai;
				}
			 set 	
				{
					bool_TrangThai=value;
				}
			}
		 private string string_TenDangNhap ;
		 public string TenDangNhap
			{
			 get 	
				{
					 return this.string_TenDangNhap;
				}
			 set 	
				{
					string_TenDangNhap=value;
				}
			}
#endregion

		/// <summary>
		/// Inserts a record into the HinhAnh table.
		/// <summary>
		/// <param name="IdHinhAnh"></param>
		/// <param name="IDChuyenMuc"></param>
		/// <param name="TenFile"></param>
		/// <param name="TenHienThi"></param>
		/// <param name="MoTa"></param>
		/// <param name="NgayUpload"></param>
		/// <param name="NgayCapNhat"></param>
		/// <param name="TrangThai"></param>
		/// <param name="TenDangNhap"></param>
		/// <returns></returns>
		public bool Insert(SqlConnection SqlCnn)
		{
			bool boolInsert = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_HinhAnh_Insert";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdHinhAnh", SqlDbType.Int).Value=IdHinhAnh;
			SqlCmd.Parameters.Add("@IDChuyenMuc", SqlDbType.Int).Value=IDChuyenMuc;
			SqlCmd.Parameters.Add("@TenFile", SqlDbType.NVarChar,100).Value=TenFile;
			SqlCmd.Parameters.Add("@TenHienThi", SqlDbType.NVarChar,100).Value=TenHienThi;
			SqlCmd.Parameters.Add("@MoTa", SqlDbType.NVarChar,100).Value=MoTa;
			SqlCmd.Parameters.Add("@NgayUpload", SqlDbType.NVarChar,20).Value=NgayUpload;
			SqlCmd.Parameters.Add("@NgayCapNhat", SqlDbType.NVarChar,20).Value=NgayCapNhat;
			SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value=TrangThai;
			SqlCmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar,50).Value=TenDangNhap;

			SqlAdp.InsertCommand = SqlCmd;
			SqlAdp.InsertCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolInsert = true;
			}
			catch
			{
			boolInsert = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolInsert;
		}

		/// <summary>
		/// Selects a single record from the HinhAnh table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable Select(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_HinhAnh_Select";
			SqlCmd.CommandType=CommandType.StoredProcedure;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
		}

		/// <summary>
		/// Selects a single record from the HinhAnh table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable SelectPrimaryKey(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_HinhAnh_SelectPrimaryKey";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdHinhAnh", SqlDbType.Int).Value=IdHinhAnh;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
			}

		/// <summary>
		/// Updates a record in the HinhAnh table.
		/// <summary>
		/// <param name="IdHinhAnh"></param>
		/// <param name="IDChuyenMuc"></param>
		/// <param name="TenFile"></param>
		/// <param name="TenHienThi"></param>
		/// <param name="MoTa"></param>
		/// <param name="NgayUpload"></param>
		/// <param name="NgayCapNhat"></param>
		/// <param name="TrangThai"></param>
		/// <param name="TenDangNhap"></param>
		public bool Update(SqlConnection SqlCnn)
		{
			bool boolUpdate = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_HinhAnh_Update";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdHinhAnh", SqlDbType.Int).Value=IdHinhAnh;
			SqlCmd.Parameters.Add("@IDChuyenMuc", SqlDbType.Int).Value=IDChuyenMuc;
			SqlCmd.Parameters.Add("@TenFile", SqlDbType.NVarChar,100).Value=TenFile;
			SqlCmd.Parameters.Add("@TenHienThi", SqlDbType.NVarChar,100).Value=TenHienThi;
			SqlCmd.Parameters.Add("@MoTa", SqlDbType.NVarChar,100).Value=MoTa;
			SqlCmd.Parameters.Add("@NgayUpload", SqlDbType.NVarChar,20).Value=NgayUpload;
			SqlCmd.Parameters.Add("@NgayCapNhat", SqlDbType.NVarChar,20).Value=NgayCapNhat;
			SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value=TrangThai;
			SqlCmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar,50).Value=TenDangNhap;

			SqlAdp.UpdateCommand = SqlCmd;
			SqlAdp.UpdateCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolUpdate = true ;
			}
			catch
			{
			boolUpdate = false ;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolUpdate;
		}

		/// <summary>
		/// Deletes a record from the HinhAnh table by a composite primary key.
		/// <summary>
		public bool Delete(SqlConnection SqlCnn)
		{
			bool boolDelete = false;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_HinhAnh_Delete";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdHinhAnh", SqlDbType.Int).Value=IdHinhAnh;

			SqlAdp.DeleteCommand = SqlCmd;
			SqlAdp.DeleteCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolDelete = true;
			}
			catch
			{
                boolDelete = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolDelete;
			}
	}
 
